﻿#ifndef URLFACTORY_H
#define URLFACTORY_H

#include <QObject>
#include <QHash>
#include <QNetworkAccessManager>

#include "TileSet.h"

#define MAX_MAP_ZOOM (23.0)

class MapProvider;

class UrlFactory : public QObject
{
    Q_OBJECT
public:
    static const char* kCopernicusElevationProviderKey;
    static const char* kCopernicusElevationProviderNotice;

    UrlFactory      ();
    ~UrlFactory     () = default;

    QNetworkRequest getTileUrl(int            id,   int x, int y, int zoom, QNetworkAccessManager* networkManager) const;
    QNetworkRequest getTileUrl(const QString& type, int x, int y, int zoom, QNetworkAccessManager* networkManager) const;

    QString getImageFormat(QString type, const QByteArray& image);
    QString getImageFormat(int id, const QByteArray& image);

    quint32  averageSizeForType  (const QString& type);

    int long2tileX(const QString& mapType, double lon, int z);
    int lat2tileY(const QString& mapType, double lat, int z);

    QHash<QString, MapProvider*> getProviderTable() const { return _providersTable; }

    int getIdFromType(const QString& type) const;
    QString getTypeFromId(const int id) const;

    MapProvider* getMapProviderFromId(int id) const;
    MapProvider* getMapProviderFromType(const QString& type) const;  // only in my code

    TileSet getTileCount(int zoom, double topleftLon, double topleftLat,
                         double bottomRightLon, double bottomRightLat,
                         const QString& mapType);

    bool isElevation(int mapId);

private:
    //int             _timeout;  // wei: defined in QGC but not use
    QHash<QString, MapProvider*> _providersTable;
    //void registerProvider(QString Name, MapProvider* provider);  // wei: defined in QGC but not use
};

#endif // URLFACTORY_H
